<?php
use \phiction\tester as t;
use \phiction\schema_loader as s;

return [
    'sanitize-name' => function () {
        t::must_equal(s::sanitize_name("hello-wor123-"), "hello-wor123-");
        t::must_equal(s::sanitize_name("--hello-wor123-"), "--hello-wor123-");
    },
    '!sanitize-name-start-num' => function () {
        s::sanitize_name("1hello-wor123-");
    },
    '!sanitize-name-empty' => function () {
        s::sanitize_name("");
    },
    'desugar-type' => function () {
        t::must_equal(s::desugar_type("?str-ing/3"), [
            'nullable' => true,
            'type' => 'str-ing',
            'max-length' => 3,
        ]);
        t::must_equal(s::desugar_type("?@user/auth"), [
            'nullable' => true,
            'type' => 'table',
            'name' => 'user',
            'from' => 'auth',
        ]);
        t::must_equal(s::desugar_type("#seq-token/auth"), [
            'nullable' => false,
            'type' => 'sequence',
            'name' => 'seq-token',
            'from' => 'auth',
        ]);
        t::must_equal(s::desugar_type("*role/auth"), [
            'nullable' => false,
            'type' => 'enum',
            'name' => 'role',
            'from' => 'auth',
        ]);
    },
    '!desugar-type-invalid-length' => function () {
        s::desugar_type("string/string-length");
    },
    '!desugar-type-zero-length' => function () {
        s::desugar_type("string/0");
    },
    '!desugar-type-negative-length' => function () {
        s::desugar_type("string/-1");
    },
    '!desugar-type-non-ext-invalid-shards' => function () {
        s::desugar_type("string/1/2");
    },
    '!desugar-type-ext-invalid-shards' => function () {
        s::desugar_type("@user/auth/api");
    },
    '!desugar-type-non-ext-invalid-name' => function () {
        s::desugar_type("!string/1");
    },
    '!desugar-type-ext-invalid-name' => function () {
        s::desugar_type("@1string/auth");
    },
    'load' => function () {
        $s = new s();
        $s->load("comment");
    },
    'scan' => function () {
        $s = new s();
        $s->scan();
        var_export($s->schemas);
    },
];

